package com.fourhats.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.fourhats.dao.QuestionableObjectDAO;
import com.fourhats.model.QuestionableObject;

@Repository
public class QuestionableObjectDAOImpl extends GenericDAOImpl<QuestionableObject, Long> implements QuestionableObjectDAO {

	protected QuestionableObjectDAOImpl() {
		super(QuestionableObject.class.getName());
	}

	@SuppressWarnings("unchecked")
	public QuestionableObject getBy(long entityId, int entityType) {
		DetachedCriteria criteria = DetachedCriteria.forEntityName(entityName);
		
        criteria.add(Restrictions.eq("entityId", entityId));
        criteria.add(Restrictions.eq("entityType", entityType));

        
        List<QuestionableObject> questionableObjects = getHibernateTemplate().findByCriteria(criteria);
        if(!questionableObjects.isEmpty()) {
        	return questionableObjects.get(0);
        }
        
        return null;
	}
}
